package com.n9.product.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 专利产品
 *
 * @author ice
 * @since 2019/1/8 14:21
 */
@Getter
@Setter
@ToString(callSuper = true)
@Entity
@Table(name = "n9_product_patent")
@DynamicUpdate
@DynamicInsert
@PrimaryKeyJoinColumn()
public class Patent extends Product {

    /**
     * 专利号
     */
    @Column(length = 16, nullable = false)
    private String no;

    /**
     * 专利类型
     */
    @Column
    @Enumerated(EnumType.STRING)
    private PatentType type;

    /**
     * 专利状态
     */
    @Column(length = 32)
    private String status;

    /**
     * 缴费截止日期
     */
    @Column
    private Date expireDate;

    /**
     * 摘要
     */
    @Basic(fetch = FetchType.LAZY)
    @Column(columnDefinition = "text")
    private String digest;

    /**
     * 优先级：数值越小，优先级越高
     */
    @Column
    private Integer priority;

    @ManyToMany(fetch=FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(joinColumns={@JoinColumn(name="patent_id")}, inverseJoinColumns={@JoinColumn(name="tag_id")})
    @OrderBy("name")
    private List<Tag> tags = new ArrayList<>(0);

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "patent")
    @Where(clause = "status='VALID'")
    private List<ReserveRecord> reserveRecords = new ArrayList<>(0);

    /**
     * 供应商ID
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn()
    private Provider provider;

    /**
     * 标签数量
     */
    @Column()
    private Integer tagCount = 0;
    /**
     * 备注
     */
    @Column
    private String notes;
}
